<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<jsp:include page="../common/menu.jsp" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<base href="<%=basePath%>">

	<title>单车月结</title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script src="<%=basePath%>js/tools.js"></script>
</head>

<body class="form-wrap">

<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-header">单车月结</div>

		<div class="layui-card-body" style="padding: 15px;">
			<form class="layui-form" action="#"
				  name="dispatchInfo" id="dispatchInfo" method="post" lay-filter="component-form-group">
				<input type="hidden" name="id" id="id" value="${settlement.id}" lay-verify="title" readonly="readonly" class="layui-input">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">车牌号</label>
						<div class="layui-input-inline">
							<input type="text" name="vehicleNum" id="vehicleNum" value="${settlement.vehicleNum}" lay-verify="title" readonly="readonly" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">操作日期</label>
						<div class="layui-input-inline">
							<input type="text" name="createTime" value="<fmt:formatDate value='${settlement.createTime}' type='time' pattern="yyyy-MM-dd"/>" readonly="readonly" lay-verify="required"
								   autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">结算年月</label>
						<div class="layui-input-inline">
							<input type="text" name="settlement" value="${settlement.settlement}" readonly="readonly" lay-verify="required"
								   autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">总营业额</label>
						<div class="layui-input-inline">
							<input type="number" readonly="readonly" name="totalMoney" id="totalMoney" value="${settlement.totalMoney}" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">总公里数</label>
						<div class="layui-input-inline">
							<input type="number" readonly="readonly" name="totalKilometres" id="totalKilometres" value="${settlement.totalKilometres}" class="layui-input">
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">油费</label>
						<div class="layui-input-inline">
							<input type="number" readonly="readonly" name="fuelMoney" id="fuelMoney" value="${settlement.fuelMoney}" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">过桥费</label>
						<div class="layui-input-inline">
							<input type="number" readonly="readonly" name="bridgeMoney" id="bridgeMoney" value="${settlement.bridgeMoney}" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">停车费</label>
						<div class="layui-input-inline">
							<input type="number" readonly="readonly" name="stopMoney" id="stopMoney" value="${settlement.stopMoney}" class="layui-input">
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">修理费</label>
						<div class="layui-input-inline">
							<input type="number" readonly="readonly" name="repairMoney" id="repairMoney" value="${settlement.repairMoney}" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">轮胎费</label>
						<div class="layui-input-inline">
							<input type="number" readonly="readonly" name="tireMoney" id="tireMoney" value="${settlement.tireMoney}" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">车补贴</label>
						<div class="layui-input-inline">
							<input type="number" readonly="readonly" name="subsidizeMoney" id="subsidizeMoney" value="${settlement.subsidizeMoney}" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">工资</label>
						<div class="layui-input-inline">
							<input type="number" name="wages" id="wages" value="${settlement.wages}" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">GPS费用</label>
						<div class="layui-input-inline">
							<input type="number" name="gpsMoney" id="gpsMoney" value="${settlement.gpsMoney}" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">保险费</label>
						<div class="layui-input-inline">
							<input type="number" name="premium" id="premium" value="${settlement.premium}" class="layui-input">
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">还贷</label>
						<div class="layui-input-inline">
							<input type="number" name="loan" id="loan" value="${settlement.loan}" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">分红</label>
						<div class="layui-input-inline">
							<input type="number" name="dividends" id="dividends" value="${settlement.dividends}" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">其他</label>
						<div class="layui-input-inline">
							<input type="number" name="otherMoney" id="otherMoney" value="${settlement.otherMoney}" class="layui-input">
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">费用总计</label>
						<div class="layui-input-inline">
							<input type="number" readonly="readonly" name="totalAmount" id="totalAmount" value="" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">毛利润</label>
						<div class="layui-input-inline">
							<input type="number" readonly="readonly" name="grossProfit" id="grossProfit" value="" class="layui-input">
						</div>
					</div>
				</div>

				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">备注</label>
					<div class="layui-input-block">
						<textarea name='remark' placeholder="请输入内容" class="layui-textarea">${settlement.remark}</textarea>
					</div>
				</div>
				<div class="layui-form-item layui-layout-admin">
					<div class="layui-input-block">
						<div class="layui-footer" style="text-align: center;">
                            <button class="layui-btn" id="save" type="button">保存</button>

							<a href="<%=basePath%>settlement/toSettlementList" class="layui-btn layui-btn-primary">返回列表</a>
						</div>
					</div>
				</div>
			</form>
		</div>

	</div>
</div>

</body>

</html>

<script>

	$('document').ready(function() {

		function getAllMoney(){
			var totalMoney = parseFloat($("#totalMoney").val());
			totalMoney = isNaN(totalMoney)?0:totalMoney;
			console.log(totalMoney);


			var t1 = parseFloat($("#fuelMoney").val());
			t1 = isNaN(t1)?0:t1;

			console.log(t1);
			var t2 = parseFloat($("#bridgeMoney").val());
			t2 = isNaN(t2)?0:t2;

			console.log(t2);
			var t3 = parseFloat($("#stopMoney").val());
			t3 = isNaN(t3)?0:t3;

			console.log(t3);
			var t4 = parseFloat($("#repairMoney").val());
			t4 = isNaN(t4)?0:t4;

			var t5 = parseFloat($("#tireMoney").val());
			t5 = isNaN(t5)?0:t5;

			var t6 = parseFloat($("#subsidizeMoney").val());
			t6 = isNaN(t6)?0:t6;

			var t7 = parseFloat($("#wages").val());
			t7 = isNaN(t7)?0:t7;

			var t8 = parseFloat($("#gpsMoney").val());
			t8 = isNaN(t8)?0:t8;

			var t9 = parseFloat($("#premium").val());
			t9 = isNaN(t9)?0:t9;

			var t10 = parseFloat($("#loan").val());
			t10 = isNaN(t10)?0:t10;

			var t11 = parseFloat($("#dividends").val());
			t11 = isNaN(t11)?0:t11;

			var t12 = parseFloat($("#otherMoney").val());
			t12 = isNaN(t12)?0:t12;


			var total = t1+t2+t3+t4+t5+t6;
			 total = total+t7+t8+t9+t10+t11+t12;
			console.log(total);
			$("#totalAmount").val(total.toFixed(2));
			$("#grossProfit").val(totalMoney-total.toFixed(2));

		}
		getAllMoney();

		$("#wages").change(function () {
			getAllMoney();
		});
		$("#gpsMoney").change(function () {
			getAllMoney();
		});
		$("#premium").change(function () {
			getAllMoney();
		});
		$("#loan").change(function () {
			getAllMoney();
		});
		$("#dividends").change(function () {
			getAllMoney();
		});
		$("#otherMoney").change(function () {
			getAllMoney();
		});

		$("#save").click(function () {
			var data = JSON.stringify($('#dispatchInfo').serializeJSON());
			$.ajax({
				type:'post'
				,url:'<%=basePath%>settlement/addSettlement'
				,data:data
				,dataType:'json'
				,contentType:'application/json;charset=utf-8'
				,success:function(data) {
					console.log(data);
					if(data.responseHead.code=200){
						window.location.href="<%=basePath%>settlement/toSettlementList";
					}else{
						layer.msg("添加失败");
					}
				}
			})
		});

		layui.use(['form','laydate'], function() {
			var $ = layui.$,
					laydate = layui.laydate,
					form = layui.form;
		});
	});
</script>

<jsp:include page="../common/js.jsp" />